package com.hongyuan.sellfitness.ui.home.view_mode;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableList;

import com.hongyuan.sellfitness.BR;
import com.hongyuan.sellfitness.R;
import com.hongyuan.sellfitness.base.Constants;
import com.hongyuan.sellfitness.base.CustomViewModel;
import com.hongyuan.sellfitness.data.MyRepository;
import com.hongyuan.sellfitness.ui.home.beans.MyMemberCardList;

import java.util.List;

import me.tatarka.bindingcollectionadapter2.ItemBinding;

public class MyMemberCardFragmentViewModel extends CustomViewModel<MyRepository> {

    public MyMemberCardFragmentViewModel(@NonNull Application application, MyRepository model) {
        super(application, model);
    }

    //给RecyclerView添加ObservableList
    public ObservableList<MyMemberCardItemViewModel> observableList = new ObservableArrayList<>();

    //给RecyclerView添加ItemBinding
    public ItemBinding<MyMemberCardItemViewModel> itemBinding = ItemBinding.of(BR.viewModel, R.layout.item_my_card);

    @Override
    protected void returnData(int code, Object dataBean) {
        super.returnData(code, dataBean);

        if(code == Constants.GET_MY_CARD_LIST){
            List<MyMemberCardList.ListBean> list = ((MyMemberCardList)dataBean).getList();

            for (MyMemberCardList.ListBean bean : list){
                MyMemberCardItemViewModel itemViewModel = new MyMemberCardItemViewModel(this,bean);
                observableList.add(itemViewModel);
            }

        }
    }
}
